#!/usr/bin/env python

import smtplib, os.path, ConfigParser
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

class ewsmail:
    
    PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
    configfile = os.path.join(PROJECT_PATH, "pyews.conf")
    config = ConfigParser.ConfigParser()
    config.read(configfile)
    sender = config.get("mail", "sender")
    destination = config.get("mail", "destination")
    
    def send(self, message):
        msg = MIMEMultipart('alternative')
        msg['Subject'] = "[ews] Info Gempa"
        msg['From'] = self.sender
        msg['To'] = self.destination
        text = message
        html = """
<html>
    <head></head>
    <body>
""" + message + \
"""
    <body>
    </body>
</html>
"""

        part1 = MIMEText(text, 'plain')
        part2 = MIMEText(text, 'html')
        msg.attach(part1)
        msg.attach(part2)
        s = smtplib.SMTP('localhost')
        s.sendmail(self.sender, self.destination, msg.as_string())
        s.quit()
